/**
 * Created by hiibook on 2017/6/15.
 */
module.exports=function (req,res,next){
    console.log("muApiPost提交用户流量使用信息更新");
    var config = require('../config/config');
    var mysql = require('mysql');
    var connection = mysql.createConnection(config.mysql);
    connection.connect();
    var registeredStatus = null;
    var query = connection.query("SELECT * FROM ss_user where id = " + req.params.id );//根据id找到用户
    query
        .on('error', function (err) {
            console.log('数据库连接失败', err)
        })
        .on('result', function (row) {
            registeredStatus = row;
        })
        .on('end', function () {
            // 更新用户数据
            var query2 = connection.query("UPDATE `" + config.mysql.database + "`.`ss_user` SET `up_data` = " + (registeredStatus.up_data + parseInt(req.body.u)) + " ,`down_data` = " +(registeredStatus.down_data +parseInt(req.body.d)) + " WHERE `ss_user`.`id` = " + req.params.id);//炒作数据库
            query2
                .on('error', function (err) {
                    console.log('数据库连接失败', err)
                })
                .on('result', function (row) {
                    console.log('用户数据更新成功');
                    registeredStatus = row;
                })
                .on('end', function () {
                    connection.end();
                    res.sendStatus(200)
                })

        })


        }

